<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div id="msgDiv">This is a sse test</div>
<script src="https://upload.shinehao.com.cn/20180816150739jquery-1.8.3.min.js"></script>
<script type="text/javascript">
        if (!!window.EventSource) {
            var source = new EventSource('http://localhost:8080/weixin/sse/workOrder/addApplyWorkOrder');
            console.log(source.readyState);
            s = ' ';

            /* message event listener */
            source.addEventListener('message', function(e) {
                s += e.data + "...<br/>";
                $("#msgDiv").html(s);
                console.info(e.data.length>0);
                if(e.data.length>0){
                	$("#audio_1").remove();
                    $("body").append('<audio id="audio_1" src="https://upload.shinehao.com.cn/mp3/newWorkOrder.mp3" controls autoplay hidden></audio>')
                }
            });

            /* open event listener */
            source.addEventListener('open', function(e) {
                console.log("Connection is open");
            }, false);

            /* error event listener */
            source.addEventListener('error', function(e) {
                if (e.readyState == EventSource.CLOSED) {
                    console.log("Connection is closed");
                } else {
                    console.log("e.readyState");
                }
            }, false);
        } else {
            alert("Your web browser dosen't support EventSource.");
        }
    </script>
</body>
</html>